package ee.mtiidla.data;

import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;

/**
 * Created by Marko on 12.10.2014.
 */
@XmlAccessorType(XmlAccessType.FIELD)
public class AgeGroup {

	@XmlAttribute(name = "agegroupid")
	private long ageGroupId;

	@XmlAttribute(name = "agemax")
	private int maxAge;

	@XmlAttribute(name = "agemin")
	private int minAge;

	@XmlAttribute(name = "gender")
	private String gender;

	@XmlAttribute(name = "name")
	private String name;

	@XmlElementWrapper(name="RANKINGS")
	@XmlElement(name = "RANKING")
	private List<Ranking> rankings;

	public long getAgeGroupId() {
		return ageGroupId;
	}

	public void setAgeGroupId(long ageGroupId) {
		this.ageGroupId = ageGroupId;
	}

	public int getMaxAge() {
		return maxAge;
	}

	public void setMaxAge(int maxAge) {
		this.maxAge = maxAge;
	}

	public int getMinAge() {
		return minAge;
	}

	public void setMinAge(int minAge) {
		this.minAge = minAge;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<Ranking> getRankings() {
		return rankings;
	}

	public void setRankings(List<Ranking> rankings) {
		this.rankings = rankings;
	}

	public String toString() {

		String result;

		if (minAge == -1 && maxAge == -1) {
			result = "Open";
		} else if (minAge == -1) {
			result = maxAge + " years and younger";
		} else if (maxAge == -1) {
			result = minAge + " years and older";
		} else {
			result = minAge + " - " + maxAge + " years";
		}

		return result + ", " + Gender.get(gender, maxAge);

	}

}

